Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Apply button_padding and drag_value_text_style applied in Slider., #5027

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rustbasic
Copy link
Contributor

@rustbasic rustbasic commented Aug 29, 2024

Improvement: button_padding applied in Slider.,
Improvement: Apply drag_value_text_style to .text_style_height() in Slider.

Removed horizontal_centered() from #4937 until a better way is found.

Before :
https://github.com/user-attachments/assets/3f8120aa-cf92-4383-a038-c3af4b768ce0

After :
https://github.com/user-attachments/assets/f0f037ff-5fd7-42bf-b9b6-277951232edc

Text Example :

use eframe::egui::*;

fn main() -> eframe::Result {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Ok(Box::<MyApp>::default())),
    )
}

#[derive(Default)]
struct MyApp {
    temp_value: usize,
    _text: String,
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.separator();

            ui.horizontal(|ui| {
                ui.add(Slider::new(&mut self.temp_value, 0..=255));

                ui.add(DragValue::new(&mut self.temp_value));

                if ui.button("⟲").clicked() {
                    self.temp_value = 255;
                }

                ui.add(Slider::new(&mut self.temp_value, 0..=255));

                ui.add(DragValue::new(&mut self.temp_value));

                if ui.button("⟲").clicked() {
                    self.temp_value = 255;
                }
            });

            ui.separator();

            ui.horizontal(|ui| {
                ui.vertical(|ui| {
                    ui.add(Slider::new(&mut self.temp_value, 0..=255).vertical());

                    ui.add(DragValue::new(&mut self.temp_value));

                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
                ui.vertical(|ui| {
                    ui.add(Slider::new(&mut self.temp_value, 0..=255).vertical());

                    ui.add(DragValue::new(&mut self.temp_value));

                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
            });

            ui.separator();

            ctx.settings_ui(ui);
        });
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant